import Vue from 'vue'
import Vuex from 'vuex'
import List from './module/list.js'
import state from './state.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state,
  getters:{
	  // getGender(state){
		 //  return '['+ state.gender +']'
	  // }
	  
	  getGender:(state) => (id) => {
	  	  return '['+ state.gender + ',' + id +']'
	  },
	  
	  //上面是es6写法 下面是一般写法
	  // getGender(state) {
	  // 	return function (id) {
	  // 		return '['+ state.gender + ',' + id +']'
	  // 	}
	  // },
  },
  mutations: {
	  increment(state) {
		  state.count++
	  },
	  setAge(state,payload){
		  state.age = payload.target.value
	  },
	  setInfo(state,value){
	  	  state.info = value
	  },
	  setName(state, value) {
	      state.name = value
	  }
  },
  //异步获取
  actions: {
	  //ES6解构语法
	  setInfo({commit}) {
		  setTimeout(()=>{
			  commit('setInfo','异步信息')
		  },1000)
	  },
	  
	  setName({commit}) {
	      setTimeout(() => {
	          commit('setName','Mr.Wang')
	      }, 1000)
	  }
  },
  modules: {
	  List
  }
})
